<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class WatchRisk
{
    protected $id;

    public function __construct($uid =  '', $oid = '', $isshow = false, $mobile = '', $order_no = 0, $id_no = 0, $merchant)
    {
        $this->uid = $uid;
        $this->oid = $oid;
        $this->isshow = $isshow;
        $this->mobile = $mobile;
        $this->order_no = $order_no ?: 0;
        $this->id_no = $id_no ?: 0;
        $this->bsign = env('BSIGN');
        $this->merchant = $merchant;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.watch-no').click(function () {
           var that = this;
           var uid = $(that).attr('data-uid');
           var oid = $(that).attr('data-oid');
           var mobile = $(that).attr('data-mobile');
           var moxie = $(that).attr('data-moxie');
           var order_no = $(that).attr('data-order-no');
           var id_no = $(that).attr('data-id-no');
           layer.open({
              type: 2, 
              content: '/html/admin/report_base.html?uid='+uid+'&oid='+oid+'&mobile='+mobile+'&moxie='+moxie+'&order_no='+order_no+'&',
              area: ['100%','100%'],
           }); 
       });
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        if($this->isshow){
            return "&nbsp;&nbsp;&nbsp;<a href='/html/admin/report.html?uid={$this->uid}&oid={$this->oid}&mobile={$this->mobile}&moxie={$this->bsign}&order_no={$this->order_no}&id_no={$this->id_no}&merchant={$this->merchant}'  class='watch' data-moxie='{$this->bsign}' data-mobile='{$this->mobile}' data-uid='{$this->uid}' data-oid='{$this->oid}'  target='_blank'><img style='width: 23px; height: 23px;' src='/images/eye.png' alt='查看报告'></a>";
        }else{
            return '';
        }

    }

    public function __toString()
    {
        return $this->render();
    }
}